<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>userAll</title>
    <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
    <link rel="stylesheet" type="text/css" href="https://cdn.bootcss.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css">
</head>
<body>
    <table class="table table-striped table-bordered table-hover table-condensed" id='tabletest' style="width: 800px" align="center">
        <tr style="text-align: center">
            <th>商品ID</th>
            <th>商品名</th>
            <th>描述</th>
            <th>操作</th>
            <th style="text-align: center"><button style="width: 100px" id="back" onclick="backwareHouse()" type="button" class="btn btn-warning">返回</button></th>
        </tr>
    </table>

</body>
    <script>
        $(document).ready(function (t) {
            $.ajax({
                type: 'GET',
                url: "http://49.235.107.34:8081/goods/findAllGoods",
                success: function (result) {
                    for (var i in result.data) {
                        $("table").append(`
            <tr style="text-align: center">
                <td>${result.data[i].goodId}</td>
                <td>${result.data[i].goodsName}</td>
                <td>${result.data[i].descripe}</td>
                <td><button id="${result.data[i].goodId}" onclick="deleteGood(this)" type="button" class="btn btn-success">删除</button></td>
            </tr>
        `);
                    }
                }

            });
        });
        
        function deleteGood(t) {
            $.ajax({
                type: 'POST',
                url: "http://49.235.107.34:8081/goods/delete",
                data: {"goodId" : t.id},
                success: function (result) {
                    if (result.code == 0){
                        /*alert("删除成功")*/
                        window.location.assign("http://49.235.107.34:8081/goodAll.html")
                    } else {
                        alert("删除失败，请重试")
                    }
                }
            })
        }

        function backwareHouse() {
            window.location.assign("http://49.235.107.34:8081/wareHouseAll.html")
        }
    </script>
</html>